package cn.wangxl.loglog.listener;

import cn.wangxl.loglog.constants.Application;
import cn.wangxl.loglog.domain.ServiceRequestLogDO;
import cn.wangxl.loglog.service.LogService;
import cn.wangxl.loglog.service.bo.BasicLogBO;
import cn.wangxl.loglog.util.DozerUtils;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description 消费数据
 * @Classname RockmqListener
 * @Created by wangxl
 * @Date 2020/5/10 23:59
 */
@Component
@RocketMQMessageListener(
        topic = "request",
        consumerGroup = "requestGroup",
        messageModel = MessageModel.CLUSTERING
)
public class RockmqRequestListener implements RocketMQListener<BasicLogBO> {

    @Autowired
    private LogService logService;

    @Override
    public void onMessage(BasicLogBO basicLogBO) {
        ServiceRequestLogDO serviceRequestLogDO = DozerUtils.convert(basicLogBO, ServiceRequestLogDO.class);
        logService.saveLog(serviceRequestLogDO,
                Application.getByName(basicLogBO.getApplication()),
                basicLogBO.getCollectionName());
    }
}
